{extend name='public/base'/}
{block name='header'}{/block} {//关掉头部}
{block name='menu'}{/block} {//关掉菜单}
{block name='seo'}
<title>{$title|default="标题"}</title>
<meta name="keywords" content="{$keywords|default='关键字'}">
<meta name="description" content="{$desc|default='描述'}">
{/block}

{block name='content'}
<article class="cl pd-20">


    <form action="" method="post" class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input  type="text" class="input-text" value="" placeholder="" id="name" name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" value=""  placeholder="密码为6位" id="password" name="password">
            </div>
        </div>



        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">启用状态：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
				<select class="select" name="status" size="1">
					<option value="1" selected>启用</option>
                    <option value="0">不启用</option>
				</select>
				</span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="email" class="input-text" placeholder="@" name="email" id="email" value="">
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">

				<select class="select" name="role" size="1">
					<option value="0" selected>教师</option>
                    <option value="1" >超级管理员</option>
                    <option value="2" >学生</option>
				</select>
				</span>
            </div>
        </div>



        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius disabled" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" id="submit" >
            </div>
        </div>
    </form>


</article>
{/block}

{block name='js'}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>




<script>

    $(function(){

        //防止用户无更新提交,只有表中数据有变化时才允许提交
        $("form").children().change(function(){
            $("#submit").removeClass('disabled');
        });

        //失去焦点时,检查用户名是否重复
        $("#name").blur(function(){
            $.ajax({
                type: 'GET',
                url: "checkUserName",
               data:{name:$(this).val()},
                dataType: 'json',
                success: function(data){
                    if (data.status == 1) {
                       alert(data.message);
                    } else {
                        alert(data.message);
                    }
                }
            });
        });

        //失去焦点时,检查邮箱是否重复
        $("#email").blur(function(){
            $.ajax({
                type: 'GET',
                url: "checkUserEmail",
                data:{email:$(this).val()},
                dataType: 'json',
                success: function(data){
                    if (data.status == 1) {
                        alert(data.message);
                    } else {
                        alert(data.message);
                    }
                }
            });
        });

        $("#submit").on("click", function(event){
            $.ajax({
                type: "POST",
                url: "{:url('user/addUser')}",
                data: $("#form-admin-add").serialize(),
                dataType: "json",
                success: function(data){
                    if (data.status == 1) {
                        alert(data.message);

                    } else {
                        alert(data.message);

                    }
                }
            });

        })
    })
</script>
{/block}

</body>
</html>